package com.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.util.Map;

/**
 * Created by dpeng on 2015/8/31.
 */
public class TraveralMap extends SimpleTagSupport{

    private String resultMap;
    private String key;
    private String val;

    public String getResultMap() {
        return resultMap;
    }

    public void setResultMap(String resultMap) {
        this.resultMap = resultMap;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getVal() {
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }

    @Override
    public void doTag() throws JspException, IOException {
        Map<Object,Object> map = (Map) getJspContext().getAttribute(resultMap);
        for(Map.Entry<Object,Object> entry : map.entrySet()) {
            key = (String) entry.getKey();
            val = (String) entry.getValue();
            getJspContext().setAttribute("key",key);
            getJspContext().setAttribute("val",val);
            getJspBody().invoke(null);
        }
    }
}
